clear all
set more off



local out2="\outregsQJE\"
cd "\workfiles"

use step001_QJE_2, clear

keep if treatment_old~=.

tsset firm_id time
tsfill

*** define treatment as given inflation TIMES treatment status
gen Treat=treatment_old*infl
gen Treat_=Treat

*** keep only the sample of firms that were not treated with ECB forecasts

*** create a flag if a firm did not participate in the survey
gen TreatF=(Treat==.)
tab TreatF

*** set treatment to zero for firms in the Treatment group 
*** that did not participate in the survey
replace Treat=0 if TreatF==1

*** restrict the sample only to the period with treatment and control groups
keep if time>=210


* foreach var in 6 12 24 48 {
foreach var in 12 {
	***======================================================
	*** 				IRF via MA estimation
	***			treat missing values as zero treatment
	*** 		Appendix Table 4
	***======================================================

	*** horizon 1
	ivreghdfe it`var'_all Treat [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", replace dta dec(3)

	***	horizon 2
	ivreghdfe it`var'_all l(0/1).Treat [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)
		
	***	horizon 3
	ivreghdfe it`var'_all l(0/2).Treat [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)
		
	***	horizon 4
	ivreghdfe it`var'_all l(0/3).Treat [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)
		
	***	horizon 5
	ivreghdfe it`var'_all l(0/4).Treat [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)
	
	
		
	***======================================================
	*** 				IRF via MA estimation
	***			do not treat missing values as zero treatment
	*** 		Table 2
	***======================================================

	*** horizon 1
	ivreghdfe it`var'_all Treat_ [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)

	***	horizon 2
	ivreghdfe it`var'_all l(0/1).Treat_ [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)
		
	***	horizon 3
	ivreghdfe it`var'_all l(0/2).Treat_ [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)
		
	***	horizon 4
	ivreghdfe it`var'_all l(0/3).Treat_ [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append dta  dec(3)
		
	***	horizon 5
	ivreghdfe it`var'_all l(0/4).Treat_ [aw=peso], ///
		 dkraay(2) absorb(i.setton5#i.trimestre)
	outreg2 using "`out2'Table02_horizonM`var'.dta", append  dta  dec(3)
	
}
